package com.baozun.houji.goods.viewmodel.state

import androidx.lifecycle.MutableLiveData
import com.baozhun.mall.common.model.bean.AppUpdateBean
import com.baozhun.mall.common.model.bean.CategoryInfoBean
import com.baozhun.mall.common.model.bean.UserInfo
import com.baozhun.mall.common.model.request.AppUpdateReqBean
import com.baozhun.mall.common.network.mCommonApiService
import com.baozhun.mall.common.util.CacheUtil
import com.baozhun.mall.common.model.HomePageBean
import com.baozun.houji.goods.model.bean.HomeGoldenBean
import com.baozun.houji.goods.network.homeApiService
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.request

/**
 *  @Title：HomeViewModel
 * @Description：
 * @Author：xuefeng.zhu
 * @Since：2022/11/4
 * @Version：1.0.0
 */
class HomeViewModel : BaseViewModel() {
    var categoryList: MutableList<CategoryInfoBean> = mutableListOf()
    var mHomeData = MutableLiveData<HomePageBean>()
    var homeGoldenBean = MutableLiveData<ArrayList<HomeGoldenBean>>()
    var isSticky = MutableLiveData<Boolean>(true)
    var userInfo = MutableLiveData<UserInfo>()
    var isLogin = MutableLiveData<Boolean>()
    var isReadPointUseTerms = MutableLiveData<Boolean>()
    var appUpdateBean = MutableLiveData<AppUpdateBean>()
    var mShowCategoryIndicator= MutableLiveData(false)

    fun getHomeData() {
        request({ mCommonApiService.getHomeData() }, success = {
            mHomeData.value = it
        }, isShowDialog = true)
    }

    fun getHomeGoldenData() {
        request({ homeApiService.getHomeGoldenData() },{
            homeGoldenBean.value = it
        })
    }
    fun requestUserInfo() {
        isLogin.value = CacheUtil.isLogin()
        if (CacheUtil.isLogin())
            request({ mCommonApiService.getUserInfo() }, {
                CacheUtil.setUser(it)
                userInfo.value = it
                isReadPointUseTerms.value = it.balance_remark_status == 1
            })
    }

    /**
     * 获取app更新信息
     */
    fun getAppUpdateInfo() {
        request({ mCommonApiService.getAppUpdateInfo(AppUpdateReqBean()) }, {
            appUpdateBean.value = it
        })
    }
}